<template>
  <view class="comment-container">
    <!-- 循环渲染评论列表 -->
    <view v-for="(comment, index) in commentList" :key="index" class="comment-item">
      <view class="comment-content">{{ comment.content }}</view>
      <view class="comment-date">{{ formaData(comment.createTime) }}</view>
    </view>
  </view>
</template>

<script>
import {commentsList} from '../../common/api'
export default {
  data() {
    return {
			userData: uni.getStorageSync('userData'),
      // 定义评论列表数据
      commentList: [
        // { content: '这是一条评论', date: '2025-04-04' },
        // { content: '另一条评论', date: '2025-04-03' }
      ]
    };
  },
	onLoad() {
		this.getList()
	},
  methods: {
		async getList(){
			let res = await commentsList(this.userData.user.coachId)
			this.commentList = res
		},
		formaData(timer) {
			const date = new Date();
			const year = date.getFullYear();
			const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始‌:ml-citation{ref="1,4" data="citationList"}
			const day = String(date.getDate()).padStart(2, '0');
			const hours = String(date.getHours()).padStart(2, '0');
			const minutes = String(date.getMinutes()).padStart(2, '0');
			const seconds = String(date.getSeconds()).padStart(2, '0');
			return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
	}
  }
};
</script>

<style>
.comment-container {
  padding: 16px;
}

.comment-item {
  background-color: #f9f9f9;
  border: 1px solid #eaeaea;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}

.comment-content {
  font-size: 16px;
  color: #333;
  margin-bottom: 15px;
}

.comment-date {
  font-size: 12px;
  color: #999;
	text-align: right;
}
</style>
